package com.typingtutor.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class OperatorUtils {

    public static String[] getAllOperators() {
        Class<?> operatorClass = OperatorUtils.class;
        Field[] fields = operatorClass.getFields();
        int staticStringFieldCount = 0;
        for (Field field : fields) {
            if (Modifier.isStatic(field.getModifiers()) && field.getType() == String.class) {
                staticStringFieldCount++;
            }
        }
        String[] operators = new String[staticStringFieldCount];
        int index = 0;
        for (Field field : fields) {
            try {
                if (Modifier.isStatic(field.getModifiers()) && field.getType() == String.class) {
                    // 获取字段的值
                    Object value = field.get(null);
                    operators[index++] = (String) value;
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return operators;
    }
}
